import { ElMessage } from 'element-plus'
import axios from 'axios'
// import router from '../router'
const get = (options) => {
	var header;
	// var staTus;
	if (options.contenttype != null) {
		header = {
			'token': localStorage.getItem('token'),
			'content-type': options.contenttype
		}
	} else {
		header = {
			'token': localStorage.getItem('token')
		}
	}
	// var res1 = '';
	axios.interceptors.response.use(function(response) {
		// res1 = response;
		return response;
	}, function(error) {
		// staTus = error.response.status
		return Promise.reject(error);
	});
	return new Promise((resolve, reject) => {
		axios({
			method: 'get',
			url: options.url,
			data: {},
			headers: header,
		}).then((res) => {
			// res1
			resolve(res)
		}).catch((err) => {
			ElMessage({
				message: '网络错误请稍后重试',
				type: 'none'
			})
			reject(err)
		})
	})
}
const post = (options) => {
	var header;
	// var staTus;
	if (options.contenttype != null) {
		header = {
			'token': localStorage.getItem('token'),
			'content-type': options.contenttype
		}
	} else {
		header = {
			'token': localStorage.getItem('token')
		}
	}
	// var res1 = '';
	axios.interceptors.response.use(function(response) {
		// res1 = response;
		return response;
	}, function(error) {
		// staTus = error.response.status
		return Promise.reject(error);
	});
	return new Promise((resolve, reject) => {
		axios({
			method: 'post',
			url: options.url,
			data: options.data,
			headers: header,
		}).then((res) => {
			// res1
			resolve(res)
		}).catch((err) => {
			ElMessage({
				message: '网络错误请稍后重试',
				type: 'none'
			})
			reject(err)
		})
	})
}

export default {
	get,
	post
}

/*
	post 请求页面调用
	var Post = this.$post;
	var data ={
		url: 'http://192.168.101.3:8885/customer/', //服务器接口地址
		data: {}, //传给后台的数据
		contenttype: 'application/x-www-form-urlencoded', //请求头数据类型
		failZt: null // null 提示网络错误弹窗  默认提示对应错误
	}
	Post(data).then((res)=>{
	    // console.log('成功'+res.data)
	},(err)=>{
	    // console.log('失败'+err.response.data)
	})
*/
